# -*- coding: utf-8 -*-

from django.db import models
from django.db.models import Q, Max, Min
from datetime import datetime

class PregaoManager(models.Manager):

    def ativos(self, *args, **kwargs):
        return self.filter(
            dt_fim__gte = datetime.now,
            dt_inicio__lte = datetime.now,
        ).filter(*args, **kwargs)

class PropostaManager(models.Manager):

    def get_maior(self, *args, **kwargs):
        max = self.aggregate(valor_max=Max('valor'))['valor_max']
        return self.get(*args, valor=max, **kwargs)

    def get_menor(self, *args, **kwargs):
        min = self.aggregate(valor_min=Min('valor'))['valor_min']
        return self.get(*args, valor=min, **kwargs)
